import { Config } from "../../Config"
import { Big, BigState } from "../core/Big"
import { Player } from "../core/Player"
import { Point } from "../core/Point"
import Utils from "../GameUtils"
import { 妖术 } from "../evolution/妖术"
import { BaseHandler } from "./BaseHandler"
import GameUtils from "../GameUtils"

export class 妖术Handler extends BaseHandler{

    妖术_敲山震虎(data:any,player:Player) {
        this.handlerMgr.spendAction(player,Config.COST_妖术_敲山震虎)
        let point = this.gameMgr.map_point.get(data.end)
        for (let point of this.gameMgr.map_point.values()) {
            point.is_敲山震虎_flag = false
        }
        let list = Utils.getArrPointsAsShan(this.gameMgr, point, new Array<Point>())
        for (let point of list) {
            let arr = Utils.getArrPointsAround(this.gameMgr, point)
            for (let pp of arr) {
                let big = pp.big as Big
                if (big != null) {
                    if (big.player != player) {
                        big.addState(BigState.FEAR)
                    }
                }
            }
        }
    }

    妖术_绝命献祭(data:any,player:Player) {
        this.handlerMgr.spendAction(player,Config.COST_妖术_绝命献祭)
        let endPoint = this.gameMgr.map_point.get(data.end)
        let startPoint = this.gameMgr.map_point.get(data.start)
        let big_start = startPoint.big
        big_start.actionOnce()
        let ys = big_start as 妖术
        let big_end = endPoint.big
        let before_number = player.arr_bigs.size
        big_end.die(player)
        let after_number = player.arr_bigs.size
        ys.immolate(before_number - after_number)
        this.gameMgr.sendBroadcast(GameUtils.getObj("play_sound",{"sound":"妖术_献祭","username":player.username}))
    }

    妖术_玄冰禁锢(data:any,player:Player) {
        this.handlerMgr.spendAction(player,Config.COST_妖术_玄冰禁锢)
        let startPoint = this.gameMgr.map_point.get(data.start)
        let big_start = startPoint.big
        big_start.actionOnce()
        let endPoint = this.gameMgr.map_point.get(data.end)
        let big_end = endPoint.big
        if (big_end == null) {
        } else {
            big_end.addState(BigState.ICE)
        }
        this.gameMgr.sendBroadcast(Utils.getObj("play_effect",{"effect":"妖术_冰冻","point_id":endPoint.id,"username":player.username}))
    }

    妖术_瘟疫传播(data:any,player:Player) {
        this.handlerMgr.spendAction(player,Config.COST_妖术_瘟疫传播)
        let startPoint = this.gameMgr.map_point.get(data.start)
        let big_start = startPoint.big
        big_start.actionOnce()
        let endPoint = this.gameMgr.map_point.get(data.end)
        let big_end = endPoint.big
        if (big_end == null) {
        } else {
            big_end.addState(BigState.METHYSIS)
        }
        this.gameMgr.sendBroadcast(Utils.getObj("play_effect",{"effect":"妖术_瘟疫","point_id":endPoint.id,"username":player.username}))
    }
}